package jm.algorithm.sort;

/**
 * @Description 冒泡排序有序退出
 * @date 2022/5/2 9:30
 */
public class BubbleSortStop<T extends Comparable<T>> extends Sort<T>{
    @Override
    protected void sort() {
        for (int end = arr.length - 1; end > 0; end--) {
            boolean sorted = true;
            for (int begin = 1; begin <= end; begin++) {
                if (cmp(begin, begin - 1) < 0){
                    swap(begin, begin-1);
                    sorted = false;
                }
            }
            if (sorted){
                break;
            }
        }
    }
}
